from django.template import Context, loader
from google.appengine.ext import db
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.utils.html import escape
from django.shortcuts import render_to_response
from site_model import site_model

def index(request):
    site_list = site_model.all()
    return render_to_response('site_list.html', {'site_list': site_list})

def addsite(request):
    if request.POST:
        item = Store()
        item.name = request.POST['store_name']
        item.telephone = request.POST['store_telephone']
        item.siteurl = request.POST['store_siteurl']
        item.feedbaseurl = request.POST['store_feedbaseurl']
        item.put()
        return HttpResponseRedirect("/stores")
    return render_to_response('store_detail.html')

def updatesite(request, sitekey):
    if request.POST:
        item = Store()
        item = db.get(storekey)
        item.name = request.POST['store_name']
        item.telephone = request.POST['store_telephone']
        item.siteurl = request.POST['store_siteurl']
        item.feedbaseurl = request.POST['store_feedbaseurl']
        item.put()
        return HttpResponseRedirect("/stores")
    item = Store()
    item = db.get(storekey)
    return render_to_response('store_detail.html', {'item': item})